package com.yunhe.common.util;

import java.util.List;

/**
 * 查询工具类
 * @desc 提供查询相关方法和参数定义
 * @author liuronglei
 */
public class Neo4jConditionUtil {
    public static String PARAMNAME_ID = "id";
    public static String PARAMNAME_LABEL = "label";
    public enum RELATION_DIRECTION {
        IN, OUT
    }
    public enum FILTERING_MODE {
        AND, OR
    }
    public enum MATCH_MODE {
        EQUALS, //等于
        NOT, //不等于
        LT, //小于
        GT, //大于
        LE, //小于等于
        GE, //大于等于
        LIKE //等于
    }
    public static String getFilteringStr(FILTERING_MODE filteringMode) {
        if (filteringMode == FILTERING_MODE.AND) {
            return "and";
        } else if (filteringMode == FILTERING_MODE.OR) {
            return "or";
        }
        return "and";
    }
    public static String getMatchStr(MATCH_MODE matchMode) {
        if (matchMode == MATCH_MODE.EQUALS) {
            return "=";
        } else if (matchMode == MATCH_MODE.NOT) {
            return "<>";
        } else if (matchMode == MATCH_MODE.LT) {
            return "<";
        } else if (matchMode == MATCH_MODE.GT) {
            return ">";
        } else if (matchMode == MATCH_MODE.LE) {
            return "<=";
        } else if (matchMode == MATCH_MODE.GE) {
            return ">=";
        } else if (matchMode == MATCH_MODE.LIKE) {
            return "=~";
        }
        return "=";
    }

    /**
     * 拼接查询条件字符串
     * @param condition 查询条件列表
     */
    public static String getConditionStr(List<String> condition) {
        StringBuilder result = new StringBuilder();
        if (condition != null && condition.size() > 0) {
            for (int i = 0; i < condition.size(); i++) {
                if (i == 0) {
                    result.append(" where");
                } else {
                    result.append(" and");
                }
                result.append(" ").append(condition.get(i));
            }
        }
        return result.toString();
    }

    /**
     * 拼接新增字符串
     * @param create 新增列表
     */
    public static String getCreateStr(List<String> create) {
        StringBuilder result = new StringBuilder();
        if (create != null && create.size() > 0) {
            for (int i = 0; i < create.size(); i++) {
                if (i == 0) {
                    result.append(" create ");
                } else {
                    result.append(",");
                }
                result.append(create.get(i));
            }
        }
        return result.toString();
    }
}
